home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / DrawCont.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  26.0 KB  |  847 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawCont.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWCONT_H
  15. #include "DrawCont.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef DRAWCLIP_H
  23. #include "DrawClip.h"
  24. #endif
  25.  
  26. #ifndef BASESHP_H
  27. #include "BaseShp.h"
  28. #endif
  29.  
  30. #ifndef GROUPSHP_H
  31. #include "GroupShp.h"
  32. #endif
  33.  
  34. #ifndef DRAWPRXY_H
  35. #include "DrawPrxy.h"
  36. #endif
  37.  
  38. #ifndef UTILS_H
  39. #include "Utils.h"
  40. #endif
  41.  
  42. #ifndef DRAWLINK_H
  43. #include "DrawLink.h"
  44. #endif
  45.  
  46. #ifndef DRWPRMSE_H
  47. #include "DrwPrmse.h"
  48. #endif
  49.  
  50. #ifndef DRAWSEL_H
  51. #include "DrawSel.h"
  52. #endif
  53.  
  54. // ----- Part Layer -----
  55.  
  56. #ifndef FWUTIL_H
  57. #include "FWUtil.h"
  58. #endif
  59.  
  60. #ifndef FWPRESEN_H
  61. #include "FWPresen.h"
  62. #endif
  63.  
  64. #ifndef FWKIND_H
  65. #include "FWKind.h"
  66. #endif
  67.  
  68. // ----- OS Layer -----
  69.  
  70. #ifndef FWRECT_H
  71. #include "FWRect.h"
  72. #endif
  73.  
  74. #ifndef FWODGEOM_H
  75. #include "FWODGeom.h"
  76. #endif
  77.  
  78. #ifndef FWSUSINK_H
  79. #include "FWSUSink.h"
  80. #endif
  81.  
  82. #ifndef FWBARRAY_H
  83. #include "FWBArray.h"
  84. #endif
  85.  
  86. #ifndef FWFILEAC_H
  87. #include "FWFileAc.h"
  88. #endif
  89.  
  90. #ifndef SLMixOS_H
  91. #include "SLMixOS.h"
  92. #endif
  93.  
  94. // ----- Foundation Layer -----
  95.  
  96. #ifndef FWSTREAM_H
  97. #include "FWStream.h"
  98. #endif
  99.  
  100. #ifndef FWSUSINK_H
  101. #include "FWSUSink.h"
  102. #endif
  103.  
  104. #ifndef FWMEMORY_H
  105. #include "FWMemory.h"
  106. #endif
  107.  
  108. // ----- OpenDoc Includes -----
  109.  
  110. #ifndef SOM_Module_OpenDoc_StdProps_defined
  111. #include <StdProps.xh>
  112. #endif
  113.  
  114. #ifndef SOM_ODTranslation_xh
  115. #include <Translt.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODShape_xh
  119. #include <Shape.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODStorageUnit_xh
  123. #include <StorageU.xh>
  124. #endif
  125.  
  126. #ifndef SOM_ODSession_xh
  127. #include <ODSessn.xh>
  128. #endif
  129.  
  130. //========================================================================================
  131. //    Runtime Information
  132. //========================================================================================
  133.  
  134. #ifdef FW_BUILD_MAC
  135. #pragma segment odfdraw
  136. #endif
  137.  
  138. FW_DEFINE_AUTO(CDrawPartContent)
  139. FW_DEFINE_AUTO(CDrawSelectionContent)
  140. FW_DEFINE_AUTO(CDrawUndoContent)
  141. FW_DEFINE_AUTO(CDrawPromiseContent)
  142. FW_DEFINE_AUTO(CDrawLinkContent)
  143. FW_DEFINE_AUTO(CDrawLinkSourceContent)
  144.  
  145. //========================================================================================
  146. //    class CDrawPartContent
  147. //========================================================================================
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    CDrawPartContent::CDrawPartContent
  151. //----------------------------------------------------------------------------------------
  152. //    CDrawPartContent constructor
  153.  
  154. CDrawPartContent::CDrawPartContent(Environment* ev, CDrawPart* part) :
  155.     CDrawContent(ev, part, FW_kZeroRect) // Size doesn't matter
  156. {
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    CDrawPartContent::~CDrawPartContent
  162. //----------------------------------------------------------------------------------------
  163. //    CDrawPartContent destructor
  164.  
  165. CDrawPartContent::~CDrawPartContent()
  166. {
  167.     FW_START_DESTRUCTOR
  168.     
  169.     if (fShapeList)
  170.     {
  171.         CBaseShape* shape;
  172.         while ((shape = fShapeList->First()) != NULL)
  173.         {
  174.             fShapeList->Remove(shape);
  175.             delete shape;
  176.         }
  177.         fProxyShapeCount = 0;
  178.     }
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. //    CDrawPartContent::PostInternalizeShape
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void CDrawPartContent::PostInternalizeShape(Environment* ev, const FW_CPoint& offset, CBaseShape* shape, short index)
  186. {
  187.     shape->OffsetShape(ev, -offset.x, -offset.y);
  188.     shape->SetExternalizationIndex(index);    // so links can find their shapes
  189. }
  190.  
  191. #if 0
  192. //----------------------------------------------------------------------------------------
  193. //    CDrawPartContent::SingleEmbeddedFrameInternalized
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void CDrawPartContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  197.                                                       FW_CEmbeddingFrame* scopeFrame,
  198.                                                       ODPart* embeddedPart, 
  199.                                                       ODFrame* embeddedFrame,
  200.                                                       ODShape* suggestedShape,
  201.                                                       ODTypeToken viewType)
  202. {
  203.     CProxyShape* insertedShape = AddSingleEmbeddedFrame(ev, 
  204.                                                         scopeFrame,
  205.                                                         embeddedPart, 
  206.                                                         embeddedFrame, 
  207.                                                         suggestedShape, 
  208.                                                         viewType);
  209.  
  210.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  211.     insertedShape->GetUpdateBox(ev, aqTempShape);
  212.  
  213.     FW_CPresentation* presentation = fDrawPart->GetMainPresentation();
  214.     CDrawFacetClipper facetClipper(fDrawPart);
  215.     facetClipper.Clip(ev, presentation, aqTempShape);
  216.  
  217.     presentation->Invalidate(ev, aqTempShape);
  218. }
  219. #endif
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    CDrawPartContent::MoveBackward
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_Boolean CDrawPartContent::MoveBackward(Environment* ev)
  226. {
  227.     FW_Boolean didIt = FALSE;
  228.  
  229.     CBaseShape* shape = fShapeList->First();
  230.     CBaseShape* previous = NULL;
  231.     while (shape != NULL)
  232.     {
  233.         if (shape->IsSelectedShape() && previous != NULL && !previous->IsSelectedShape())
  234.         {
  235.             fShapeList->Remove(shape);
  236.             fShapeList->AddBefore(previous, shape);            
  237.             shape->MovedBefore(ev, previous);
  238.             shape = previous;            
  239.             didIt = TRUE;
  240.         }
  241.         else
  242.             previous = shape;
  243.         
  244.         shape = fShapeList->After(shape);
  245.     }
  246.  
  247.     return didIt;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    CDrawPartContent::MoveForward
  252. //----------------------------------------------------------------------------------------
  253.  
  254. FW_Boolean CDrawPartContent::MoveForward(Environment* ev)
  255. {
  256.     FW_Boolean didIt = FALSE;
  257.     
  258.     CBaseShape* shape = fShapeList->Last();
  259.     CBaseShape* next = NULL;
  260.     while (shape != NULL)
  261.     {
  262.         if (shape->IsSelectedShape() && next != NULL && !next->IsSelectedShape())
  263.         {
  264.             fShapeList->Remove(shape);
  265.             fShapeList->AddAfter(next, shape);            
  266.             shape->MovedAfter(ev, next);
  267.             shape = next;            
  268.             didIt = TRUE;
  269.         }
  270.         else
  271.             next = shape;
  272.             
  273.         shape = fShapeList->Before(shape);
  274.     }
  275.         
  276.     return didIt;
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    CDrawPartContent::MoveToBack
  281. //----------------------------------------------------------------------------------------
  282.  
  283. void CDrawPartContent::MoveToBack(Environment* ev)
  284. {
  285.     CShapeCollection extract;
  286.     ExtractSelection(ev, &extract);
  287.     
  288.     CShapeCollectionIterator ite(&extract);
  289.     for (CBaseShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  290.     {
  291.         fShapeList->AddFirst(shape);
  292.         shape->MovedFirst(ev);
  293.     }
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. //    CDrawPartContent::MoveToFront
  298. //----------------------------------------------------------------------------------------
  299.  
  300. void CDrawPartContent::MoveToFront(Environment* ev)
  301. {
  302.     CShapeCollection extract;
  303.     ExtractSelection(ev, &extract);
  304.     
  305.     CShapeCollectionIterator ite(&extract);
  306.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  307.     {
  308.         fShapeList->AddLast(shape);
  309.         shape->MovedLast(ev);
  310.     }
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. //    CDrawPartContent::ExtractSelection
  315. //----------------------------------------------------------------------------------------
  316.  
  317. void CDrawPartContent::ExtractSelection(Environment* ev, CShapeCollection* extract)
  318. {
  319. FW_UNUSED(ev);
  320.     // ----- Create the extract list -----
  321.     CShapeCollectionIterator ite(fShapeList);
  322.     CBaseShape* shape;
  323.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  324.     {
  325.         if (shape->IsSelectedShape())
  326.             extract->AddLast(shape);
  327.     }
  328.         
  329.     // ----- Remove then from the shape list -----
  330.     CShapeCollectionIterator ite2(extract);
  331.     for (shape = ite2.First(); ite2.IsNotComplete(); shape = ite2.Next())
  332.     {
  333.         fShapeList->Remove(shape);
  334.     }
  335. }
  336.  
  337. //----------------------------------------------------------------------------------------
  338. //    CDrawPartContent::NewShape
  339. //----------------------------------------------------------------------------------------
  340.  
  341. CBaseShape* CDrawPartContent::NewShape(Environment* ev, unsigned short shapeType)
  342. {    
  343. FW_UNUSED(ev);
  344.     CBaseShape *theShape = NULL;
  345.  
  346.     FW_ASSERT(shapeType != kProxyShape);        // We should never create a proxyShape this way
  347.     
  348.     switch (shapeType)
  349.     {
  350.         case kLineShape:
  351.             theShape = FW_NEW(CLineShape, (fDrawPart));
  352.             break;
  353.             
  354.         case kTextShape:
  355.             theShape = FW_NEW(CTextShape, (fDrawPart));
  356.             break;
  357.         
  358.         case kRectShape:
  359.             theShape = FW_NEW(CRectShape, (fDrawPart));
  360.             break;
  361.             
  362.         case kOvalShape:
  363.             theShape = FW_NEW(COvalShape, (fDrawPart));
  364.             break;
  365.             
  366.         case kRRectShape:
  367.             theShape = FW_NEW(CRoundRectShape, (fDrawPart));
  368.             break;
  369.     }
  370.     
  371.     return theShape;
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. //    CDrawPartContent::NewPromise
  376. //----------------------------------------------------------------------------------------
  377.  
  378. FW_CPromise* CDrawPartContent::NewPromise(    Environment* ev, 
  379.                                             ODStorageUnit* su, 
  380.                                             FW_StorageKinds storageKind, 
  381.                                             FW_CCloneInfo* cloneInfo)
  382. {
  383.     // Part caontent can only be asked to promise itself  in CloneInto, in which case it's necessary
  384.     // first test for existence of kODPropContentFrame
  385.     
  386.     if (!su->Exists(ev, kODPropContentFrame, (ODValueType)NULL, 0))
  387.         return NULL;
  388.         
  389.     // The promise resolver in OpenDoc seems to choke when trying to fulfill a promise made to a
  390.     // link during a drop.  For a link of intrinsic content, the net result (besides an assertion failure
  391.     // in debug version of openDoc) is that the destination doesn't update.  But when the promise was
  392.     // written in the cloneInto method of a single embedded frame, the resultant failure inevitably 
  393.     // leads to a crash.  The difference of is that in the first case, as soon as the link dest attempts
  394.     // to read the content, the operation fails, leaving the destination intact.  In the single frame
  395.     // case, the container, which owns the link dest, has no problem reading the embedded frame.  The 
  396.     // failure occurs as the new embedded part attempts to initialize from storage.  This apparently leaves
  397.     // the container in a bad state, so it crashes the next time an update is attempted.
  398.     
  399.     // for now, we'll avoid that situation:
  400.     if (storageKind == FW_kLinkStorage)
  401.         return NULL;
  402.     
  403.     // ----- Make a copy of myself -----
  404.     CDrawPromiseContent* promisedContent = FW_NEW(CDrawPromiseContent, (ev, fDrawPart, this));
  405.  
  406.     // ----- Create a promise object -----
  407.     return new CDrawPromise(ev, storageKind, cloneInfo, promisedContent);
  408. }
  409.  
  410.  
  411. //========================================================================================
  412. //    class CDrawSelectionContent
  413. //========================================================================================
  414.  
  415. //----------------------------------------------------------------------------------------
  416. //    CDrawSelectionContent::CDrawSelectionContent
  417. //----------------------------------------------------------------------------------------
  418. //    CDrawSelectionContent constructor
  419.  
  420. CDrawSelectionContent::CDrawSelectionContent(Environment* ev, CDrawPart* part, CDrawSelection* selection) :    
  421.     CDrawContent(ev, part, selection->GetDragRect()),
  422.     fDrawSelection(selection)
  423. {
  424.     FW_END_CONSTRUCTOR
  425. }
  426.  
  427. //----------------------------------------------------------------------------------------
  428. //    CDrawSelectionContent::~CDrawSelectionContent
  429. //----------------------------------------------------------------------------------------
  430. //    CDrawSelectionContent destructor
  431.  
  432. CDrawSelectionContent::~CDrawSelectionContent()
  433. {
  434.     FW_START_DESTRUCTOR
  435. }
  436.  
  437. //----------------------------------------------------------------------------------------
  438. //    CDrawSelectionContent::NewPromise
  439. //----------------------------------------------------------------------------------------
  440.  
  441. FW_CPromise* CDrawSelectionContent::NewPromise(Environment* ev, ODStorageUnit* su, FW_StorageKinds storageKind, FW_CCloneInfo* cloneInfo)
  442. {
  443. FW_UNUSED(su);
  444.  
  445.     // update our content rect before copying self for promise.
  446.     fContentRect = fDrawSelection->GetDragRect();
  447.     
  448.     // ----- Make a copy of myself -----
  449.     CDrawPromiseContent* promisedContent = FW_NEW(CDrawPromiseContent, (ev, fDrawPart, this));
  450.  
  451.     // ----- Create a promise object -----
  452.     return new CDrawPromise(ev, storageKind, cloneInfo, promisedContent);
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. //    CDrawSelectionContent::SingleEmbeddedFrameInternalized
  457. //----------------------------------------------------------------------------------------
  458.  
  459. void CDrawSelectionContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  460.                                                           FW_CEmbeddingFrame* scopeFrame,
  461.                                                           ODPart* embeddedPart, 
  462.                                                           ODFrame* embeddedFrame,
  463.                                                           ODShape* suggestedShape,
  464.                                                           ODTypeToken viewType)
  465. {
  466.     fDrawSelection->CloseSelection(ev);
  467.     CProxyShape* insertedShape = AddSingleEmbeddedFrame(ev, 
  468.                                                         scopeFrame, 
  469.                                                         embeddedPart, 
  470.                                                         embeddedFrame, 
  471.                                                         suggestedShape, 
  472.                                                         viewType);    
  473.     PostInternalizeShape(ev, FW_kZeroPoint, insertedShape, 1);                                        
  474. }
  475.  
  476. //----------------------------------------------------------------------------------------
  477. //    CDrawSelectionContent::PostInternalizeShape
  478. //----------------------------------------------------------------------------------------
  479.  
  480. void CDrawSelectionContent::PostInternalizeShape(Environment* ev, const FW_CPoint& offset, CBaseShape* shape, short index)
  481. {
  482. FW_UNUSED(offset);
  483.     shape->SetExternalizationIndex(index);    // so links can find their shapes
  484.  
  485.     // ----- Add the shape to the right places -----
  486.     fDrawPart->AddShapeToPart(ev, shape);    // Add to the part data
  487.     
  488.     // ----- Shape has already been added to the selection list (fShapeList)
  489.     fDrawSelection->ShapeAdded(ev, shape);
  490. }
  491.  
  492. //----------------------------------------------------------------------------------------
  493. //    CDrawSelectionContent::AcquireSuggestedFrameShape
  494. //----------------------------------------------------------------------------------------
  495.  
  496. ODShape* CDrawSelectionContent::AcquireSuggestedFrameShape(Environment* ev)
  497. {
  498.     FW_CRect selectionRect = fDrawSelection->GetDragRect();
  499.     selectionRect.Place(FW_kZeroPoint);
  500.     
  501.     return ::FW_NewODShape(ev, selectionRect);
  502. }
  503.  
  504. //========================================================================================
  505. //    class CDrawUndoContent
  506. //========================================================================================
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    CDrawUndoContent::CDrawUndoContent
  510. //----------------------------------------------------------------------------------------
  511. //    CDrawUndoContent constructor
  512.  
  513. CDrawUndoContent::CDrawUndoContent(Environment* ev, CDrawPart* part, CDrawSelection* selection) :
  514.     CDrawContent(ev, part, selection->GetDrawContent(ev)),
  515.     fDrawSelection(selection)
  516. {
  517.     FW_END_CONSTRUCTOR
  518. }
  519.  
  520. //----------------------------------------------------------------------------------------
  521. //    CDrawUndoContent::~CDrawUndoContent
  522. //----------------------------------------------------------------------------------------
  523. //    CDrawUndoContent destructor
  524.  
  525. CDrawUndoContent::~CDrawUndoContent()
  526. {
  527.     FW_START_DESTRUCTOR
  528. }
  529.  
  530. //----------------------------------------------------------------------------------------
  531. //    CDrawUndoContent::RemoveShapeSelection
  532. //----------------------------------------------------------------------------------------
  533.  
  534. void CDrawUndoContent::RemoveShapeSelection(Environment *ev)
  535. {
  536.     // Select the saved shapes
  537.     fDrawSelection->SelectContent(ev, this);
  538.  
  539.     // Clear the selected shapes
  540.     fDrawSelection->ClearSelection(ev);
  541.  
  542. }
  543.  
  544. //----------------------------------------------------------------------------------------
  545. //    CDrawUndoContent::RestoreShapeSelection
  546. //----------------------------------------------------------------------------------------
  547.  
  548. void CDrawUndoContent::RestoreShapeSelection(Environment *ev)
  549. {
  550.     // Add the saved shapes back into the part
  551.     CDrawContentShapeIterator ite(this);
  552.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  553.     {
  554.         shape->RestoreShape(ev);
  555.     }
  556.  
  557.     // Redraw the restored shapes
  558.     RedrawShapes(ev);
  559.  
  560.     // Select the saved shapes
  561.     fDrawSelection->SelectContent(ev, this);
  562. }
  563.  
  564. //----------------------------------------------------------------------------------------
  565. //    CDrawUndoContent::DeleteSavedShapes
  566. //----------------------------------------------------------------------------------------
  567.  
  568. void CDrawUndoContent::DeleteSavedShapes(Environment *ev)
  569. {
  570.     CBaseShape* shape;
  571.     
  572.     // Before deleting the shapes, make sure they are not promised
  573.     CDrawContentShapeIterator ite(this);
  574.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  575.     {
  576.         shape->CheckPromise(ev);
  577.     }
  578.     
  579.     // ----- Delete all the saved shapes -----
  580.     while ((shape = GetFirstShape()) != NULL)
  581.     {
  582.         RemoveShape(ev, shape);
  583.         delete shape;
  584.     }        
  585. }
  586.  
  587. //----------------------------------------------------------------------------------------
  588. //    CDrawUndoContent::RemoveFromLinks
  589. //----------------------------------------------------------------------------------------
  590. void CDrawUndoContent::RemoveFromLinks(Environment* ev)
  591. {
  592.     // Remove the saved shapes from any link sources they're in
  593.     CDrawContentShapeIterator it(this);
  594.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  595.     {
  596.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  597.         if (linkSource)
  598.         {
  599.             linkSource->RemoveShape(ev, shape);
  600.         }
  601.  
  602.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  603.         if (link)
  604.         {
  605.             link->Unregister(ev);
  606.             fDrawPart->GetLinkManager(ev)->RemoveFromDestLinkList(ev, link);
  607.         }
  608.     }
  609. }
  610.  
  611. //----------------------------------------------------------------------------------------
  612. //    CDrawUndoContent::RestoreLinks
  613. //----------------------------------------------------------------------------------------
  614. void CDrawUndoContent::RestoreLinks(Environment* ev)
  615. {
  616.     // Add the saved shapes back into any link sources they were in
  617.     CDrawContentShapeIterator it(this);
  618.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  619.     {
  620.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  621.         if (linkSource)
  622.         {
  623.             linkSource->AddShape(ev, shape);
  624.         }
  625.         
  626.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  627.         if (link)
  628.         {
  629.             link->Register(ev, fDrawPart);
  630.             fDrawPart->GetLinkManager(ev)->AddToDestLinkList(ev, link);
  631.         }
  632.     }
  633. }
  634.  
  635. //----------------------------------------------------------------------------------------
  636. //    CDrawUndoContent::DeleteEmptyLinkSources
  637. //----------------------------------------------------------------------------------------
  638. void CDrawUndoContent::DeleteEmptyLinkSources(Environment* ev)
  639. {
  640.     // Check for link sources left empty because all their shapes were removed
  641.     FW_CLinkManager* linkMgr = fDrawPart->GetLinkManager(ev);
  642.  
  643.     CDrawContentShapeIterator it(this);
  644.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  645.     {
  646.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  647.         if (linkSource && linkSource->IsEmpty())
  648.         {
  649.             linkMgr->BreakSourceLink(ev, linkSource);
  650.             delete linkSource;
  651.         }
  652.     }
  653. }
  654.  
  655. //----------------------------------------------------------------------------------------
  656. //    CDrawUndoContent::DeleteSavedShapesAndLinks
  657. //----------------------------------------------------------------------------------------
  658. void CDrawUndoContent::DeleteSavedShapesAndLinks(Environment* ev)
  659. {
  660.     CBaseShape* shape;
  661.     
  662.     // Before deleting the shapes, make sure they are not promised
  663.     CDrawContentShapeIterator ite(this);
  664.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  665.     {
  666.         shape->CheckPromise(ev);
  667.     }
  668.     
  669.     // ----- Delete all the saved shapes -----
  670.     while ((shape = GetFirstShape()) != NULL)
  671.     {
  672.         RemoveShape(ev, shape);
  673.         // Check for an orphaned link and delete it
  674.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  675.         if (link)
  676.             delete link;    // deletes the shape
  677.         else
  678.             delete shape;
  679.     }        
  680. }
  681.  
  682. //========================================================================================
  683. //    class CDrawPromiseContent
  684. //========================================================================================
  685.  
  686. //----------------------------------------------------------------------------------------
  687. //    CDrawPromiseContent::CDrawPromiseContent
  688. //----------------------------------------------------------------------------------------
  689. //    CDrawPromiseContent constructor
  690.  
  691. CDrawPromiseContent::CDrawPromiseContent(Environment* ev, 
  692.                                         CDrawPart* part, 
  693.                                         CDrawContent* content) :
  694.     CDrawContent(ev, part, content)
  695. {
  696.     FW_END_CONSTRUCTOR
  697. }
  698.  
  699. //----------------------------------------------------------------------------------------
  700. //    CDrawPromiseContent::~CDrawPromiseContent
  701. //----------------------------------------------------------------------------------------
  702. //    CDrawPromiseContent destructor
  703.  
  704. CDrawPromiseContent::~CDrawPromiseContent()
  705. {
  706.     FW_START_DESTRUCTOR
  707. }
  708.  
  709. //----------------------------------------------------------------------------------------
  710. //    CDrawPromiseContent::IsOKtoWrite
  711. //----------------------------------------------------------------------------------------
  712.  
  713. FW_Boolean CDrawPromiseContent::IsOKtoWrite(Environment* ev, CBaseShape* shape)
  714. {
  715. FW_UNUSED(ev);
  716. FW_UNUSED(shape);
  717.     return TRUE;
  718. }
  719.  
  720. //----------------------------------------------------------------------------------------
  721. //    CDrawPromiseContent::PromiseShape
  722. //----------------------------------------------------------------------------------------
  723.  
  724. void CDrawPromiseContent::PromiseShape(Environment* ev, FW_StorageKinds storageKind, FW_Boolean state)
  725. {
  726. FW_UNUSED(ev);
  727.     CDrawContentShapeIterator ite(this);
  728.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  729.         shape->Promised(storageKind, state);
  730. }
  731.  
  732.  
  733. //========================================================================================
  734. //    class CDrawLinkSourceContent
  735. //========================================================================================
  736.  
  737. //----------------------------------------------------------------------------------------
  738. //    CDrawLinkSourceContent::CDrawLinkSourceContent
  739. //----------------------------------------------------------------------------------------
  740. //    CDrawLinkSourceContent constructor
  741.  
  742. CDrawLinkSourceContent::CDrawLinkSourceContent(    Environment* ev, 
  743.                                                 CDrawPart* part, 
  744.                                                 CDrawContent* selectedContent,
  745.                                                 CDrawPublishLink* linkSrc) :
  746.     CDrawPromiseContent(ev, part, selectedContent),
  747.     fLinkSource(linkSrc)
  748. {
  749.     FW_END_CONSTRUCTOR
  750. }
  751.  
  752. //----------------------------------------------------------------------------------------
  753. //    CDrawLinkSourceContent::~CDrawLinkSourceContent
  754. //----------------------------------------------------------------------------------------
  755. //    CDrawLinkSourceContent destructor
  756.  
  757. CDrawLinkSourceContent::~CDrawLinkSourceContent()
  758. {
  759.     FW_START_DESTRUCTOR
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //    CDrawLinkSourceContent::NewPromise
  764. //----------------------------------------------------------------------------------------
  765. FW_CPromise* CDrawLinkSourceContent::NewPromise(Environment* ev,  ODStorageUnit* su, FW_StorageKinds storageKind,  FW_CCloneInfo* cloneInfo)//Override
  766. {
  767. FW_UNUSED(su);
  768.  
  769.     // ----- Create a promise object -----
  770.     return new CDrawPromise(ev, storageKind, cloneInfo, this, fLinkSource);
  771. }
  772.  
  773.  
  774. //========================================================================================
  775. //    class CDrawLinkContent
  776. //========================================================================================
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    CDrawLinkContent::CDrawLinkContent
  780. //----------------------------------------------------------------------------------------
  781. //    CDrawLinkContent constructor
  782.  
  783. CDrawLinkContent::CDrawLinkContent(Environment* ev, CDrawPart* part, CDrawSubscribeLink* link) :
  784.     CDrawContent(ev, part, FW_kZeroRect),
  785.     fLink(link)
  786. {
  787.     // This constructor is called when a new destination link is created
  788. }
  789.  
  790. //----------------------------------------------------------------------------------------
  791. //    CDrawLinkContent::CDrawLinkContent
  792. //----------------------------------------------------------------------------------------
  793. //    CDrawLinkContent constructor
  794.  
  795. CDrawLinkContent::CDrawLinkContent(Environment* ev, CDrawSubscribeLink* link, CDrawPart* part, CDrawLinkContent* content)
  796. :    CDrawContent(ev, part, content),
  797.     fLink(link)
  798. {
  799.     // This constructor is called when a link is updated (not the first time)
  800.     FW_END_CONSTRUCTOR
  801. }
  802.  
  803. //----------------------------------------------------------------------------------------
  804. //    CDrawLinkContent::~CDrawLinkContent
  805. //----------------------------------------------------------------------------------------
  806. //    CDrawLinkContent destructor
  807.  
  808. CDrawLinkContent::~CDrawLinkContent()
  809. {
  810.     FW_START_DESTRUCTOR
  811. }
  812.  
  813. //----------------------------------------------------------------------------------------
  814. //    CDrawLinkContent::GroupShapes
  815. //----------------------------------------------------------------------------------------
  816. void CDrawLinkContent::GroupShapes(Environment* ev, CGroupShape* group)
  817. {
  818. FW_UNUSED(ev);
  819.     // Add our shapes to the group shape
  820.     CDrawContentShapeIterator it(this);
  821.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  822.     {
  823.         group->AddShape(shape);
  824.     }
  825. }
  826.  
  827. //----------------------------------------------------------------------------------------
  828. //    CDrawLinkContent::SingleEmbeddedFrameInternalized
  829. //----------------------------------------------------------------------------------------
  830.  
  831. void CDrawLinkContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  832.                                                        FW_CEmbeddingFrame* scopeFrame,
  833.                                                        ODPart* embeddedPart, 
  834.                                                        ODFrame* embeddedFrame,
  835.                                                        ODShape* suggestedShape,
  836.                                                        ODTypeToken viewType)
  837. {
  838.     CProxyShape* newShape = AddSingleEmbeddedFrame(ev, 
  839.                                                    scopeFrame, 
  840.                                                    embeddedPart, 
  841.                                                    embeddedFrame, 
  842.                                                    suggestedShape, 
  843.                                                    viewType);
  844.     PostInternalizeShape(ev, FW_kZeroPoint, newShape, 1);                                                
  845. }
  846.  
  847.